<?php

// Include
include_once('plugin/SmartyPlugin.php');
include_once('plugin/LoginPlugin.php');
include_once('plugin/AppConfigPlugin.php');
include_once('plugin/SecurityAccessPlugin.php');
include_once('plugin/CommonPlugin.php');

// Para establecer locale en espanol (evita problemas como el formateo de la fecha de Smarty)
setlocale (LC_TIME,"spanish");

// Chequea si el usuario ya esta logueado
if (!LoginPlugin::isLogged()) {
	header( 'Location: index.php' );
	exit;		
}

// Current script
$currentScript = AppConfigPlugin::getCurrentScript();
$currentPage = AppConfigPlugin::curPageURL();



$currentUrl = AppConfigPlugin::curPageURL();
//echo $currentUrl;

// Ejecucion
$username = LoginPlugin::getUsername();
$rol = LoginPlugin::getRol();

$menuItems = AppConfigPlugin::getMenuItems($rol);
$manageItems = AppConfigPlugin::getManageItems();
$appInfo = AppConfigPlugin::getAppInfo();
$iconsImg = AppConfigPlugin::getIconsImg();

// Mensaje
$message = CommonPlugin::getMessage();
CommonPlugin::setMessage("");

// Creacion de Smarty
$smarty = SmartyPlugin::getSmarty();
$smarty->assign('menuItems', $menuItems);
$smarty->assign('manageItems', $manageItems);
$smarty->assign('appInfo', $appInfo);
$smarty->assign('iconsImg', $iconsImg);
$smarty->assign('username', $username);
$smarty->assign('rol', $rol);
$smarty->assign('message', $message);
$smarty->assign('googleAPI', $google_api);

// Breadcrumb
//$breadcrumb = AppConfigPlugin::getBreadcrumb(basename($_SERVER['PHP_SELF']));
//$smarty->assign('breadcrumb', $breadcrumb);

// Sons
$sons = AppConfigPlugin::getSons(basename($_SERVER['PHP_SELF']));
$smarty->assign('sons', $sons);
$smarty->assign('currentScript', $currentScript);
$smarty->assign('currentPage', $currentPage);

$menuItems = AppConfigPlugin::getMenuItems(null);

if ($currentUrl != 'ajaxSaveImputado.php' && $currentUrl  != 'ajaxDeleteImputado.php'){
	if (!SecurityAccessPlugin::hasAccess($menuItems, $currentUrl, $manageItems, $rol)) {
		echo "No se puede mostrar";
		//$smarty->display('noaccess.tpl');
		//exit();
	}
}
